#!/usr/bin/env python
# encoding: utf-8
'''
@author: qiuyan
@contact: winston@peipeiyun.com
@file: wap_server.py
@time: 20120/2/13 6:27 PM
@desc:
'''

from sanic.response import html,text
from core import app,template
from core.temp_render import render
from apis.urls import api_group_bp
app.blueprint(api_group_bp)

import sys
from signal import signal, SIGINT
import asyncio
import uvloop

if __name__ == '__main__':

    if sys.platform=='win32':
        try:
            port = int(sys.argv[1])
        except:
            port = 8000
        app.run(host="0.0.0.0", port=port, debug=True)
    else:
        try:
            port = int(sys.argv[1])
        except:
            port = 7000
        asyncio.set_event_loop(uvloop.new_event_loop())
        server = app.create_server(host="0.0.0.0", port=port, return_asyncio_server=True,access_log=True)
        loop = asyncio.get_event_loop()
        task = asyncio.ensure_future(server)
        signal(SIGINT, lambda s, f: loop.stop())
        try:
            loop.run_forever()
        except:
            loop.stop()
